import Cookies from 'js-cookie'

const TokenKey = 'token'
const NameKey = 'Name'
const userIdKey = 'userId'
const headImgKey = 'headImg'

export function getToken() {
    return Cookies.get(TokenKey)
}

export function setToken(token) {
    return Cookies.set(TokenKey, token)
}

export function removeToken() {
    return Cookies.remove(TokenKey)
}
export function getHeadImg() {
    return Cookies.get(headImgKey)
}

export function setHeadImg(headImg) {
    return Cookies.set(headImgKey, headImg)
}

export function removeHeadImg() {
    return Cookies.remove(headImgKey)
}
export function getUserId() {
    return Cookies.get(userIdKey)
}

export function setUserId(userId) {
    return Cookies.set(userIdKey, userId)
}

export function removeUserId() {
    return Cookies.remove(userIdKey)
}

export function getName() {
    return Cookies.get(NameKey)
}

export function setName(name) {
    return Cookies.set(NameKey, name)
}

export function removeName() {
    return Cookies.remove(NameKey)
}

export function getCookie(cookieName) {
    return Cookies.get(cookieName)
}

export function setCookie(cookieName, value) {
    return Cookies.set(cookieName, value)
}

export function removeCookie(cookieName) {
    return Cookies.remove(cookieName)
}

export const storage = {

    set(key, value) {
        localStorage.setItem(key, JSON.stringify(value))
    },
    get(key) {
        return JSON.parse(localStorage.getItem(key))
    },
    remove(key) {
        localStorage.removeItem(key)
    },
    clear() {
        localStorage.clear()
    }
}
export const session = {
    set(key, value) {
        sessionStorage.setItem(key, JSON.stringify(value))
    },
    get(key) {
        return JSON.parse(sessionStorage.getItem(key))
    },
    remove(key) {
        sessionStorage.removeItem(key)
    },
    clear() {
        sessionStorage.clear()
    }
}